<?php
include './config/config.php';

function create_guid($prefix = ""){    
    $str = md5(uniqid(mt_rand(), true));   
    $uuid  = substr($str,0,8) . '-';   
    $uuid .= substr($str,8,4) . '-';   
    $uuid .= substr($str,12,4) . '-';   
    $uuid .= substr($str,16,4) . '-';   
    $uuid .= substr($str,20,12);   

    return $prefix . $uuid;
}
//页面标识
$guid = create_guid();

//echo $config['push']['baseurl'] . ':'. $config['push']['port'];
//die;
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">

<script src='https://cdn.bootcss.com/socket.io/2.0.3/socket.io.js'></script>
<script src='//cdn.bootcss.com/jquery/1.11.3/jquery.js'></script>
<script src='/static/js/notify.js'></script>
</head>
<body>

<div class="notification sticky hide">
    <p id="content"> </p>
</div>
<div class="wrapper">
    <div style="width:850px;">
        <img src='<?php $config['local']['baseurl'] . ':'. $config['local']['port'];?>/qrcode.php?guid=<?php echo $guid;?>' />
    </div>
</div>
<div class='footer'>
    <p id="online_box"> </p>
</div>

<script>
$(document).ready(function () {
    
    // 连接服务端
    var socket = io("<?php echo $config['push']['baseurl'] . ':'. $config['push']['port']['socketio'];?>");
    // 连接后登录
    socket.on('connect', function(){
    	socket.emit('login', '<?php echo $guid;?>');
    });
    // 后端推送来消息时
    socket.on('new_msg', function(msg){
         $('#content').html('收到消息：'+msg);
         $('.notification.sticky').notify();
    });
    // 后端推送来在线数据时
    socket.on('update_online_count', function(online_stat){
        $('#online_box').html(online_stat);
    });
});
</script>

</body>
</html>


